package com.jsle.common.artifactory;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jsle.financial.domain.User;
/**
 * User`s context
 * @author wisdying
 * @date 2012-11-10
 */
@SuppressWarnings("unchecked")
public class UserContext {
	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(UserContext.class);

	private static final Set login = Collections.synchronizedSet(new HashSet());
	/**
	 * 添加在线人员信息
	 * @param user
	 */
	public static void setOnlineUser(User user) {
		
		if(!isExsit(user)){
			login.add(user);
		}
	}
	
	private static boolean isExsit(User user){
		boolean result = false;
		for (Iterator it = login.iterator(); it.hasNext();) {
			User loginUser = (User) it.next();
			if(loginUser.hashCode()==user.hashCode()){
				result = true;
			}
		}
		return result;
	}
	/**
	 * 删除掉线的人员信息
	 * @param user
	 */
	public static void removeOnlineUser(User user){
		login.remove(user);
	}
	
	public static Set getLogin() {
		return login;
	}
	
	
}
